*------------------------------PLEASE READ-------------------------------------*

/*

REPLICATION FILE FOR TABLES 1 AND B1
AUTHOR: ZHENHUAN LEI & YISHUANG LI
DATE: 11/13/2023
SOFTWARE: STATA 17 SE OPERATED ON WINDOWS 11

STATA PACKAGE NEEDED: 
	ssc install estout, replace 
*/

*-------------------------- Set up the environment ---------------------------*
clear 
use ../data/case_data.dta

***Rescale and define varibales
	gen dispute_contract = (dispute == 1)
	gen dispute_loans = (dispute == 2 )
	gen dispute_accident_liability = (dispute == 3)  
	gen dispute_torts = (dispute == 4)
	gen dispute_others = (dispute == 9)  
	gen intermediate_court = (court_level == 2)
	gen stake_million = stake_bi * 1000 
	replace debt_rate = debt_rate / 100 // ranging from 0 ro 1
	replace reg_cap_bi = reg_cap_bi * 1000 // billion Yuan
	gen trial_length = trial_year - accept_year
	replace trial_length = . if trial_length < 0
	

***Defining variable lists
	global litigation_var_1 local_plaintiff plaintiff firm1_local stake_million intermediate_court trial_year other_pro win_up dispute_contract dispute_loans dispute_accident_liability dispute_torts dispute_others  
	global firm_var1 total_return_rate net_profit debt_rate net_cash_flow reg_cap_bi firm_age employee_num firm_pc pr_govsub pr_tax  
	
	global reform_var centralize_city50 centralize_city0 reform_cont local_win_low local_win_up local_win_final enforce_1y_low  enforce_quality_low
	global litigation_var local_plaintiff firm1_local stake_million intermediate_court trial_year  dispute_contract dispute_loans dispute_accident_liability dispute_torts dispute_others plaintiff other_pro trial_length
	global firm_var total_return_rate net_profit debt_rate net_cash_flow reg_cap_bi firm_age employee_num pr_govsub pr_tax firm_pc manufacture real_estate
	global cont_city gdp_percapita_c gdp_growth_c population_hr_c  publicfinance_income_c publicfinance_expenditure_c city_total_ipo tax_vadded_c investment_fixed_c population_unemployed_c gdp_secondary_c gdp_tertiary_c 
	


***data_sampling
	gen data_sample = (court_level == 2 | court_level == 1) & (arbitration == 0 & reconcile == 0) //basic or intermediate court; no arbitration and reconciling before trial; non_missing on provincial data  
	replace data_sample = 0 if court_level == 2 & municipal == 1  //drop intermediate courts in municipalities
	keep if data_sample == 1
	format $reform_var $litigation_var $firm_var1 $firm_var $litigation_var_1 $cont_city %6.3f 
	

*-------------------------- Regression analysis -------------------------------*
***Table 1***
	bysort centralize_city50: sum($litigation_var_1 $firm_var1) if !mi(centralize_city50), format

	eststo clear
	foreach x of varlist $litigation_var_1  $firm_var1{
		eststo: qui reg `x' centralize_city50 , cluster(city_id)
	}
esttab, b(3) p(3) star(* 0.1 ** 0.05 *** 0.01) keep(centralize_city50)


***Table B2*** 

	sum $reform_var $litigation_var $firm_var $cont_city , format

